-
An
MGLStyleAnnotationController
is the object responsible for adding, removing, and updatingMGLStyleAnnotation
s on a map.Do not create instances of
See moreMGLStyleAnnotationController
directly. Instead, create an instance ofMGLCircleAnnotationController
,MGLLineAnnotationController
,MGLPolygonAnnotationController
, orMGLSymbolAnnotationController
and use-[MGLAnnotationController addShape:]
or-[MGLStyleAnnotationController addShapes:]
to add shapes to anMGLMapView
.Declaration
Objective-C
@interface MGLAnnotationController : NSObject
Swift
class MGLAnnotationController : NSObject
-
An
MGLCircleAnnotationController
is a controller that creates internally instances of anMGLShapeSource
andMGLCicleStyleLayer
to simplify the creation of runtime styling based annotations to the map.Create instances of
MGLCircleStyleAnnotation
and pass it to this controller to add circular shapes to anMGLMapView
.Example
See morefunc mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) { let circleAnnotationController = MGLCircleAnnotationController(mapView: self.mapView) let circle = MGLCircleStyleAnnotation(center: CLLocationCoordinate2D(latitude: 59.31, longitude: 18.06), radius: 3.0, color: .blue) circle.opacity = 0.5 circleAnnotationController.add(circle) }
Declaration
Objective-C
@interface MGLCircleAnnotationController : MGLAnnotationController
Swift
class MGLCircleAnnotationController : MGLAnnotationController
-
An
MGLLineAnnotationController
is a controller that creates internally instances of anMGLShapeSource
andMGLLineStyleLayer
to simplify the creation of runtime styling based annotations to the map.Create instances of
MGLLineStyleAnnotation
and pass it to this controller.Example
See morefunc mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) { let lineAnnotationController = MGLLineAnnotationController(mapView: self.mapView) let lineCoordinates = [ CLLocationCoordinate2D(latitude: 59, longitude: 18), CLLocationCoordinate2D(latitude: 60, longitude: 20) ] let line = MGLLineStyleAnnotation(coordinates: lineCoordinates, count: UInt(lineCoordinates.count)) line.color = .purple lineAnnotationController.add(line) }
Declaration
Objective-C
@interface MGLLineAnnotationController : MGLAnnotationController
Swift
class MGLLineAnnotationController : MGLAnnotationController
-
An
MGLPolygonAnnotationController
is a controller that creates internally instances of anMGLShapeSource
andMGLFillStyleLayer
to simplify the creation of runtime styling based annotations to the map.Create instances of
MGLPolygonStyleAnnotation
and pass it to this controller.Example
See morefunc mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) { let polygonAnnotationController = MGLPolygonAnnotationController(mapView: self.mapView) let polygonCoordinates = [ CLLocationCoordinate2DMake(59, 18), CLLocationCoordinate2DMake(62, 19), CLLocationCoordinate2DMake(54, 20), CLLocationCoordinate2DMake(59, 18) ] let polygon = MGLPolygonStyleAnnotation(coordinates: polygonCoordinates, count: UInt(polygonCoordinates.count)) polygon.fillOutlineColor = .red polygonAnnotationController.add(polygon) }
Declaration
Objective-C
@interface MGLPolygonAnnotationController : MGLAnnotationController
Swift
class MGLPolygonAnnotationController : MGLAnnotationController
-
An
MGLSymbolAnnotationController
is a controller that creates internally instances of anMGLShapeSource
andMGLSymbolStyleLayer
to simplify the creation of runtime styling based annotations to the map.Create instances of
MGLSymbolStyleAnnotation
and pass it to this controller.An image must be supplied to the map style’s sprite before being able to assign it to be the icon image of a symbol.
Example
See morefunc mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) { let attraction = UIImage(named: "attraction") if let styleImage = attraction { self.mapView.style?.setImage(styleImage, forName: "attraction") } let symbolAnnotationController = MGLSymbolAnnotationController(mapView: self.mapView) let symbol = MGLSymbolStyleAnnotation(coordinate: CLLocationCoordinate2DMake(59, 18)); symbol.iconImageName = "attraction" symbol.text = "This is a cool place!" symbol.textFontSize = 16 symbolAnnotationController.add(symbol) }
Declaration
Objective-C
@interface MGLSymbolAnnotationController : MGLAnnotationController
Swift
class MGLSymbolAnnotationController : MGLAnnotationController